package com.example.fw;

import org.openqa.selenium.By;

import com.example.tests.ContactData;

public class ContactHelper extends HelperBase {

	public ContactHelper(ApplicationManager manager) {
		super(manager);

	}

	public void submitContactForm() {
		click(By.name("submit"));
	}

	public void fillContactForm(ContactData contact) {
		type(By.name("firstname"), contact.firstName);
		type(By.name("lastname"), contact.lastName);
		type(By.name("address"), contact.primaryHomeAddress);
		type(By.name("home"), contact.homePhone);
		type(By.name("mobile"), contact.mobilePhone);
		type(By.name("work"), contact.workPhone);
		type(By.name("email"), contact.email1);
		type(By.name("email2"), contact.email2);
		type(By.name("byear"), contact.yearOfBirth);
		type(By.name("address2"), contact.address2);
		type(By.name("phone2"), contact.phone2);
		if (contact.dayOfBirth != null) {
			selectByText(By.name("bday"), contact.dayOfBirth);
		}
		if (contact.monthOfBirth != null) {
			selectByText(By.name("bmonth"), contact.monthOfBirth);
		}
		driver.findElement(By.name("byear")).clear();
		driver.findElement(By.name("byear")).sendKeys(contact.yearOfBirth);
		/*
		 * if (contact.contactGroupName != null) {
		 * selectByText(By.name("new_group"), contact.contactGroupName); }
		 */
	}

	public void initContactCreation() {
		click(By.linkText("add new"));
	}

	public void initContactModification(int index) {
		click(By.xpath("//img[@title ='Edit'][" + index + "]"));

	}

	public void submitContactModificationForm() {
		click(By.name("update"));

	}

	public void submitContactRemoval() {
		click(By.xpath("//input[@value ='Delete']"));
		
	}

}
